FROM adoptopenjdk:8-jre-hotspot as builder
WORKDIR application
ARG JAR_FILE=target/*.jar
COPY ${JAR_FILE} application.jar
RUN java -Djarmode=layertools -jar application.jar extract

FROM adoptopenjdk:8-jre-hotspot
WORKDIR application
ENV TIME_ZONE=Asia/Shanghai
ENV JAVA_OPTS_EXT=""
ENV JAVA_OPTS="-server -Xms2048m -Xmx2048m -Xmn768m -XX:+UseG1GC -XX:+DisableExplicitGC -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/var/log/app/jvm_dump.hprof -Dfile.encoding=UTF-8 "
RUN ln -snf /usr/share/zoneinfo/$TIME_ZONE /etc/localtime && echo $TIME_ZONE > /etc/timezone
COPY --from=builder application/dependencies/ ./
COPY --from=builder application/spring-boot-loader/ ./
COPY --from=builder application/snapshot-dependencies/ ./
COPY --from=builder application/application/ ./
ENTRYPOINT ["/bin/bash", "-c","java ${JAVA_OPTS_EXT} ${JAVA_OPTS} org.springframework.boot.loader.JarLauncher"]
